﻿Imports System.Configuration
Imports System.Data.SqlClient
Imports SIGI.Common.BE

Public Class QuestionDAC

#Region "<< -Search- >>"
    Public Shared Function Search() As List(Of QuestionBE)
        Dim wSqlConn As SqlConnection = Nothing
        Dim wSqlCmd As SqlCommand = Nothing
        Dim wReader As SqlDataReader = Nothing
        Dim wConnStr As String = String.Empty

        Dim wQuestionList As List(Of QuestionBE) = Nothing
        Dim wQuestionBE As QuestionBE = Nothing

        Try
            'Obtengo la cadena de conexión
            wConnStr = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            'Creo la conexión a la BD
            wSqlConn = New SqlConnection(wConnStr)
            'Creo el comando
            wSqlCmd = New SqlCommand()
            wSqlCmd.Connection = wSqlConn
            wSqlCmd.CommandType = CommandType.StoredProcedure
            wSqlCmd.CommandText = "Preguntas_s"

            'Abro la conexión a la BD
            wSqlConn.Open()

            wQuestionList = New List(Of QuestionBE)
            wReader = wSqlCmd.ExecuteReader()
            While wReader.Read
                wQuestionBE = New QuestionBE

                wQuestionBE.Id = Convert.ToInt32(wReader("Id_Pregunta"))
                wQuestionBE.Description = Convert.ToString(wReader("Pregunta"))

                wQuestionList.Add(wQuestionBE)
            End While

            wSqlConn.Close()
        Catch ex As Exception
            Throw ex
        Finally
            wReader = Nothing
            wSqlCmd = Nothing
            wSqlConn = Nothing
        End Try

        Return wQuestionList
    End Function
#End Region

End Class
